package com.example.lynandroid

import android.app.Activity
import android.util.Log
import android.view.View
import com.example.lynandroid.enum.LifeType
import kotlin.math.roundToInt

fun log(msg: String) {
    Log.e("WILYN", msg)
}

fun bootLog(msg: String) {
    Log.e("BOOT", msg)
}

fun dp2px(dp: Int): Int {
    return (dp * App.getContext().resources.displayMetrics.density).roundToInt()
}

fun View.gone() {
    visibility = View.GONE
}

fun View.visible() {
    visibility = View.VISIBLE
}

fun View.visibleToggle() {
    if (visibility == View.VISIBLE) {
        gone()
    } else {
        visible()
    }
}

fun lifeLog(name: String?, lifeType: LifeType) {
    name?.let {
        log("${name}  ${getLifeString(lifeType)}")
    }
}

fun screenWidth(): Int {
    return App.getContext().resources.displayMetrics.widthPixels
}

fun screenHeight(): Int {
    return App.getContext().resources.displayMetrics.heightPixels
}

fun screenWidth(activity: Activity): Int {
    return activity.resources.displayMetrics.widthPixels
}

fun screenHeight(activity: Activity): Int {
    return activity.resources.displayMetrics.heightPixels
}

fun getLifeString(lifeType: LifeType): String {
    return when (lifeType) {
        LifeType.Create -> "Create"
        LifeType.Restart -> "ReStart"
        LifeType.Start -> "Start"
        LifeType.Resume -> "Resume"
        LifeType.Pause -> "Pause"
        LifeType.Stop -> "Stop"
        LifeType.Destroy -> "Destroy"
        LifeType.AttachToWindow -> "AttachToWindow"
        LifeType.DetachFromWindow -> "DetachFromWindow"
        LifeType.Draw -> "Draw"
        LifeType.Layout -> "Layout"
        LifeType.Measure -> "Measure"
        LifeType.VisibleChange -> "VisibleChange"
        LifeType.Attach -> "Attach"
        LifeType.CreateView -> "CreateView"
        LifeType.DestroyView -> "DestroyView"
        LifeType.Detach -> "Detach"
        LifeType.ViewCreated -> "ViewCreated"
        LifeType.OnSaveInstanceState -> "OnSaveInstanceState"
        LifeType.WindowFocusChange -> "WindowFocusChange"
        LifeType.FinishInflater -> "FinishInflater"
    }
}